#!/usr/bin/python
import matplotlib.pyplot as plt
import random
import numpy as np
import time
thetastd=50
te=2

def mean(todolist):
	return sum(todolist)/len(todolist)

def geterror(pacNumber,theta,nt):
	yi=[]
	for i in range(0,pacNumber):
		xi=random.gauss(1,13)
		yi.append(nt+theta+xi)
	thetaEstm=mean(yi)-nt
	error=theta-thetaEstm
	return error

err1=[]
err3=[]
err4=[]
err5=[]
err6=[]
err7=[]
rounds=1000
repeats=500
avg1=[]
avg3=[]
avg4=[]
avg5=[]
avg6=[]
avg7=[]

for t in range(repeats):
	for i in range(rounds):
		err1.append(abs(geterror(1,thetastd,te)))
		err3.append(abs(geterror(3,thetastd,te)))
		err4.append(abs(geterror(4,thetastd,te)))
		err5.append(abs(geterror(5,thetastd,te)))
		err6.append(abs(geterror(6,thetastd,te)))
		err7.append(abs(geterror(7,thetastd,te)))
	avg1.append(np.mean(err1))
	avg3.append(np.mean(err3))
	avg4.append(np.mean(err4))
	avg5.append(np.mean(err5))
	avg6.append(np.mean(err6))
	avg7.append(np.mean(err7))
	err1=[]
	err3=[]
	err4=[]
	err5=[]
	err6=[]
	err7=[]
	print "repeats ",t," done! at: ",time.asctime()

plt.plot(range(repeats),avg1,label="$DMTS$")
plt.plot(range(repeats),avg3,'.',label="$3\ pkts$")
#plt.plot(range(repeats),avg4,':',label="$4 pkts$")
plt.plot(range(repeats),avg5,'+',label="$5\ pkts$")
#plt.plot(range(repeats),avg6,',',label="$6 pkts$")
plt.plot(range(repeats),avg7,'*',label="$7\ pkts$")
plt.xlabel("repeats")
plt.ylabel("error(us)")
plt.xticks(range(0,repeats,repeats/10))
plt.legend(bbox_to_anchor=(0.1,1.05),loc=3,ncol=6,borderaxespad=0)
plt.show()
